<template>
  <div id="hotel-orders">
    <div class="card bg-transparent">
      <div class="card-header">
        <nav aria-label="breadcrumb" role="navigation">
          <ol class="breadcrumb pb-0">
            <li class="breadcrumb-item active" aria-current="page">酒店订单</li>

            <li class="breadcrumb-item ms-auto">
              <router-link to="/hotel/search">酒店预订</router-link>
            </li>
          </ol>
        </nav>
      </div>
      <div class="card-body py-1">
        <form>
          <div class="row">
            <div class="col-1">
              <my-date-picker
                id="beginDate"
                v-model="beginDate"
                name="sc.beginDate"
                placeholder="开始日期"
              ></my-date-picker>
            </div>
            <div class="col-1">
              <my-date-picker
                id="endDate"
                v-model="endDate"
                name="sc.endDate"
                placeholder="截止日期"
              ></my-date-picker>
            </div>
            <div class="col-1">
              <input
                type="textfield"
                class="form-control"
                size="6"
                placeholder="订单号"
                v-model.trim="orderNo"
              />
            </div>
            <div class="col-2">
              <my-select-customer
                :status="1"
                :customerId.sync="customerId"
                :enterpriseType="1"
              ></my-select-customer>
            </div>
            <div class="col-1">
              <input
                type="textfield"
                class="form-control ms-1"
                size="10"
                placeholder="入住人"
                v-model.trim="name"
              />
            </div>
            <div class="col-1">
              <input
                type="textfield"
                class="form-control ms-1"
                size="10"
                placeholder="酒店名称"
                v-model.trim="hotelName"
              />
            </div>
            <div class="col-1">
              <select
                class="form-select"
                v-model.number="status"
                name="sc.status"
              >
                <option value="-1">订单状态</option>
                <option value="0">未提交</option>
                <option value="10">待审批</option>
                <option value="20">待处理</option>
                <option value="1">处理中</option>
                <option value="2">已完成</option>
                <option value="4">已取消</option>
              </select>
            </div>

            <div class="col">
              <button
                type="button"
                class="btn btn-primary ms-1"
                @click.stop="search()"
              >
                查找
              </button>
              <button
                type="button"
                class="btn btn-sm btn-secondary ms-1"
                @click.stop="reset()"
              >
                重置
              </button>

              <router-link to="/hotel/order" class="btn btn-success float-end"
                >新建</router-link
              >
            </div>
          </div>
        </form>
      </div>

      <nav id="pagination-box-1" class="float-end">
        <my-pagination
          name="pagination"
          :row-count="sc.rowCount"
          :page-total="sc.pageTotal"
          :page-no="sc.pageNo"
          @next-page="nextPage"
          @prev-page="prevPage"
          @direct-page="directPage"
        ></my-pagination>
      </nav>

      <hotel-order-list :dataList="dataList"></hotel-order-list>

      <nav id="pagination-box-2" class="float-end">
        <my-pagination
          name="pagination"
          :row-count="sc.rowCount"
          :page-total="sc.pageTotal"
          :page-no="sc.pageNo"
          @next-page="nextPage"
          @prev-page="prevPage"
          @direct-page="directPage"
        ></my-pagination>
      </nav>
    </div>
  </div>
</template>

<script>
import { searchHotelOrders, showHotelOrderStatus } from "@/api/hotel.js";
import MyDatePicker from "@/components/my-datepicker.vue";
import MyPagination from "@/components/my-pagination.vue";

import MySelectCustomer from "@/components/my-select2-customer.vue";

import HotelOrderList from "@/components/list/hotel-order-list.vue";

export default {
  components: {
    MyDatePicker,
    MyPagination,
    MySelectCustomer,
    HotelOrderList,
  },
  data() {
    return {
      dataList: [],
      customers: [],
      sc: {
        rowCount: 0,
        pageNo: 1,
        pageSize: 20,
        pageTotal: 0,
      },
      beginDate: "",
      endDate: "",
      orderNo: "",
      customerId: -1,
      name: "",
      hotelName: "",
      status: -1,
    };
  },
  mounted: function () {
    // this.search()
  },
  activated: function () {
    if (window.matchMedia("(max-width: 576px)").matches) {
      console.log(this.$router);
      this.$router.replace("/h5/hotel/orders");
    } else {
      this.search();
    }
  },
  methods: {
    showErrMsg: function (msg, msgType) {
      this.$store.dispatch("showAlertMsg", {
        errMsg: msg,
        errMsgType: msgType,
      });
    },
    showLoading: function (loadingText) {
      this.$store.commit("showLoading", {
        loading: true,
        loadingText: loadingText,
      });
    },
    hideLoading: function () {
      this.$store.commit("showLoading", {
        loading: false,
      });
    },
    search: function () {
      this.showLoading();
      const params = {
        "sc.pageNo": this.sc.pageNo,
        "sc.pageSize": this.sc.pageSize,
        "sc.beginDate": this.beginDate,
        "sc.orderNo": this.orderNo,
        "sc.endDate": this.endDate,
        "sc.customerId": this.customerId,
        "sc.name": this.name,
        "sc.hotelName": this.hotelName,
        "sc.status": this.status,
      };
      searchHotelOrders(
        params,
        (v) => {
          this.dataList = v.dataList;
          this.sc = v.page;

          // if (v.dataList.length === 0) {
          //   this.showErrMsg('没找到任何东西')
          // }
        },
        () => {
          this.hideLoading();
        }
      );
    },
    reset: function () {
      this.beginDate = "";
      this.endDate = "";
      this.orderNo = "";
      this.customerId = -1;
      this.name = "";
      this.hotelName = "";
      this.status = -1;
    },
    getStatusDesc: function (status) {
      return showHotelOrderStatus(status);
    },
    prevPage: function () {
      this.sc.pageNo = this.sc.pageNo - 1;
      if (this.sc.pageNo < 1) this.sc.pageNo = 1;
      this.search();
    },
    nextPage: function () {
      this.sc.pageNo = this.sc.pageNo + 1;
      this.search();
    },
    directPage: function (pageNo) {
      this.sc.pageNo = pageNo;
      this.search();
    },
  },
};
</script>
